import Spark from "./Spark";
/**
 * create a Fire
 * @class
 */
class Fire {
    constructor(ctx, canvas, y, config) {
        this.ctx = ctx;
        this.canvas = canvas;
        this.y = y;
        this.config = config;
        this.sparks = [];
        this.fps = true;
    }

    spark (x) {
        if (this.fps) {
            this.sparks.push(new Spark(this.ctx, this.canvas, x, this.y, this.config));
            this.fps = false;
            window.setTimeout( e => { this.fps = true; }, 80 );
        }
    }

    update () {
        for (let i = 0; i < this.sparks.length; i++) {
            if (this.sparks[i].update()) {
                this.sparks.splice(i, 1);
            }
        }
    }
}

export default Fire;